package com.java.synchronized_.question.code_block;

/**
 * 都有锁，锁对象不同
 */
public class QuestionB {
    public static void func() {
        System.out.println(Thread.currentThread().getName() + "开始");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "结束");
    }
    
    public static void main(String[] args) {
        Object object1 = new Object();
        Object object2 = new Object();
        
        new Thread(() -> {
            synchronized (object1) {
                func();
            }
        }).start();
        
        new Thread(() -> {
            synchronized (object2) {
                func();
            }
        }).start();
    }
    
    /**
     * 输出结果如下
     * Thread-0开始
     * Thread-1开始
     * Thread-1结束
     * Thread-0结束
     */
}
